package cn.com.generaldata.os.service.indicator_evaluation.national_economy_contribution;

import org.apache.commons.lang3.Validate;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 涉海就业直接贡献率评估指标计算类.
 */
public class OceanRelatedEmployedContributionCalculateService extends IndicatorEvaluationCalculateService {

	private String oceanRelatedEmployedIndicatorName = ProvinceIndicatorConstant.OCEAN_EMPLOYED_INDICATOR_NAME;
	private String employedIndicatorName = ProvinceIndicatorConstant.EMPLOYED_INDICATOR_NAME;

	@SuppressWarnings("null")
	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {

		Double currentOceanRelatedEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear(), oceanRelatedEmployedIndicatorName);
		Validate.isTrue(currentOceanRelatedEmployedCount != null);

		Double prevOceanRelatedEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear() - 1, oceanRelatedEmployedIndicatorName);
		Validate.isTrue(prevOceanRelatedEmployedCount != null);

		Double currentEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear(), employedIndicatorName);
		Validate.isTrue(currentEmployedCount != null);

		Double prevEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear() - 1, employedIndicatorName);
		Validate.isTrue(prevEmployedCount != null);

		if (Double.valueOf(0).equals(currentEmployedCount - prevEmployedCount)) {
			return Double.valueOf(0);
		}

		return (currentOceanRelatedEmployedCount - prevOceanRelatedEmployedCount)
				/ (currentEmployedCount - prevEmployedCount) * 100;
	}

}
